package online.afeibaili.storebackendframework.util

import org.springframework.http.ResponseEntity

fun <T> ok(data: T): ResponseEntity<T> = ResponseEntity.ok(data)
fun ok(code: Int, data: Any): ResponseEntity<Map<String, Any>> =
    ResponseEntity.ok(mapOf("code" to code, "data" to data))

fun ok(code: Int, message: String): ResponseEntity<Map<String, Any>> =
    ResponseEntity.ok(mapOf("code" to code, "message" to message))

infix fun Int.message(message: String): ResponseEntity<Map<String, Any>> =
    ResponseEntity.ok(mapOf("code" to this, "message" to message))

infix fun Int.data(data: Any): ResponseEntity<Map<String, Any>> =
    ResponseEntity.ok(mapOf("code" to this, "data" to data))

fun response(action: () -> Response): Response {
    return action.invoke()
}